package com.qumall.boot.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qumall.boot.entity.User;
import com.qumall.boot.mapper.UserMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class UserService extends ServiceImpl<UserMapper, User> {

    public User getByUsername(String username) {
        // 访问数据库的耗时统计
        long start = System.currentTimeMillis();
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>().eq("account", username)
                .or().eq("email", username)
                .or().eq("phone", username);
        User one = getOne(queryWrapper);
        log.info("getByUsername 耗时统计 {}ms", System.currentTimeMillis() - start);
        return one;
    }

    public User getByPhone(String account) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<User>().eq("phone", account);
        return getOne(queryWrapper);
    }
}
